
$(function(){
    $('#selectedEducation').bootstrapTable({
        url: '/EducationManager/selectEducation',
        method: 'get',
        showRefresh: true,  //显示刷新按钮
        search: true,
        toolbar:'#toolbar',
        striped : true,     //设置为true会有隔行变色效果
        //sidePagination:'server',//服务器端分页默认接受rows和total
        pagination:true,//客户端分页
        sidePagination:'client',
        idFiled:'educationId',
        pageNumber:1,
        pageSize:10,
        columns: [
            {
                field: 'checkId',
                checkbox:true,
                clickToSelect:true
            }, {
                field: 'educationId',
                title: 'id'
            }
            , {
                field: 'educationDesc',
                title: '学历描述'
            }]
    });
});

var vm = new Vue({
    el:'#SelectEducation',
    data:{
        showList:1,

        educationDescrip:'',


        educationDescrip2:'',
        Education:{educationId:'',educationDesc:''}
    },
    methods: {
        //***start选课的方法***
        //选课按钮
        add: function () {
            // 弹出选课对话框
            $('#addEducation').modal("show");
            },
        // 选课提交按钮
        submit: function () {
            //获取下拉列表所选的value

            var desc=$('#educationDescrip').val();

            vm.Education.educationDesc=desc;
            if (desc==null){//选中了提示的option
                layer.alert('检查输入');
                return
            }
            $.ajax({
                type: "POST",//post方法默认是表单数据提交，用requestParameter接收，如果要用jason需要配置在conmmon.js中的第一行有配置
                url: '/EducationManager/addEducation',//请求的controller
                data: JSON.stringify(vm.Education),//参数
                success: function (r) {
                    if (r > 0) {
                        layer.alert('添加成功');
                        //更新表格
                        vm.educationDescrip=null;
                        $('#selectedEducation').bootstrapTable('refresh');
                    }
                },
                error: function () {
                    layer.alert('失败');
                }
            });
        },
        //退选
        del: function () {
            var rows = $("#selectedEducation").bootstrapTable('getSelections');

            if (rows.length == 0) {
                layer.alert('请选择至少一条记录');
                return;
            } else {
                layer.confirm('您确定删除吗？', {
                    btn: ['确定', '取消'] //可以无限个按钮
                }, function(index, layero){
                    var ids = new Array();
                    //遍历所有选择的行数据，取每条数据对应的ID
                    $.each(rows, function(i, row) {
                        ids[i] = row['educationId'];
                    });
                    console.log(ids);
                    $.ajax({
                        type: "POST",
                        url: "/EducationManager/delEducation",
                        data: JSON.stringify(ids),
                        success : function(r) {
                            if(r===true){
                                layer.alert('删除成功');
                                $('#selectedEducation').bootstrapTable('refresh');
                            }else{
                                layer.alert("失败");
                            }
                        },
                        error : function() {
                            layer.alert('服务器没有返回数据，可能服务器忙，请重试');
                        }
                    });
                });
            }
        },
        upd: function () {
            // 弹出选课对话框

            var rows = $("#selectedEducation").bootstrapTable('getSelections');
            if (rows.length != 1) {
                layer.alert('请选择一条记录');
                return;
            } else {
                $('#updEducation').modal("show");


                vm.educationDescrip2=rows[0].educationDesc;
            }
        },
        // 选课提交按钮
        submit2: function () {



            //获取下拉列表所选的value
            var rows = $("#selectedEducation").bootstrapTable('getSelections');


            var desc=$('#educationDescrip2').val();

            vm.Education.educationDesc=desc;
            vm.Education.educationId=rows[0].educationId;

            if (desc==''||desc==null){//选中了提示的option
                layer.alert('检查输入');
                return
            }
            $.ajax({
                type: "POST",//post方法默认是表单数据提交，用requestParameter接收，如果要用jason需要配置在conmmon.js中的第一行有配置
                url: '/EducationManager/updEducation',//请求的controller
                data: JSON.stringify(vm.Education),//参数
                success: function (r) {
                    if (r >0) {
                        layer.alert('修改成功');
                        vm.Education.educationId=null;
                        $('#updEducation').modal("hide");
                        $('#selectedEducation').bootstrapTable('refresh');
                    }
                },
                error: function () {

                    layer.alert('失败');
                }
            });
        }
        //***end选课的方法***


    }
    //***end实验的方法***

})

